var jsonList = {};
var page = 1;
var rows = 10;
$(function (){ 
    //搜索
    //搜索
    $(".state").change(function () {
        var result = $(this).val();
        if (result == 1) {
            jsonList.disable = true;
        } else {
            jsonList.disable = false;
        }
    })
    $(".btn_sh").on("click", function () {
        var sou_vl = $(".sou_vl").val();//
        if (sou_vl != "") {
            jsonList.query = sou_vl;
        }
        getList();

    })
    //禁用
    $('.dis').click(function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要禁用该用户吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/app/user/disable/true?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('禁用失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一个用户禁用');

        }
    })
    //取消禁用
    $('.endis').click(function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要取消禁用该用户吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/app/user/disable/false?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('取消禁用失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一个用户');

        }
    })
    //删除
    $('.del').click(function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要删除该用户吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/app/user/remove?ids="+ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('删除用户失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一个用户');

        }
    })
})

getList();
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/app/user/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".user_list").empty();
                $(list).each(function (index, key) {
                   
                    html += `<tr>
                        <td>  <input type="checkbox" class="arc_isc" oid="${key.id}"/></td>
                        <td>${key.id}</td>
                        <td>${key.disable?"是":"否"}</td>
                        <td>${key.username?key.username:""}</td>
                        <td>${key.role?key.role:""}</td>
                        <td>${key.nickname?key.nickname:""}</td>
                        <td>${key.version?key.version:"" }</td>
                        <td>${key.loginIp?key.loginIp:""}</td>
                        <td>${key.loginTime?key.loginTime:""}</td>
                    </tr>`;
                })
                $(".user_list").append(html);
            }
        }

    })
    //分页
}